Ubuntu 16.04
Sponsored Link

OpenStack Ocata : Boot Instances
2017/03/12
 
Create and Start Virtual Machine Instance.
[1] Specify the flavor (memory or disk) and create an instance and boot it.
# create a flavor

root@dlp ~(keystone)#
openstack flavor create --id 0 --vcpus 1 --ram 2048 --disk 10 m1.small

+----------------------------+----------+
| Field                      | Value    |
+----------------------------+----------+
| OS-FLV-DISABLED:disabled   | False    |
| OS-FLV-EXT-DATA:ephemeral  | 0        |
| disk                       | 10       |
| id                         | 0        |
| name                       | m1.small |
| os-flavor-access:is_public | True     |
| properties                 |          |
| ram                        | 2048     |
| rxtx_factor                | 1.0      |
| swap                       |          |
| vcpus                      | 1        |
+----------------------------+----------+

root@dlp ~(keystone)#
openstack flavor list

+----+----------+------+------+-----------+-------+-----------+
| ID | Name     |  RAM | Disk | Ephemeral | VCPUs | Is Public |
+----+----------+------+------+-----------+-------+-----------+
| 0  | m1.small | 2048 |   10 |         0 |     1 | True      |
+----+----------+------+------+-----------+-------+-----------+

# show the list of images

root@dlp ~(keystone)#
openstack image list

+--------------------------------------+------------+--------+
| ID                                   | Name       | Status |
+--------------------------------------+------------+--------+
| 3e88d891-e286-426b-ad6b-4c97920d16be | Ubuntu1604 | active |
+--------------------------------------+------------+--------+

# show the list of network

root@dlp ~(keystone)#
openstack network list

+--------------------------------+------------+--------------------------------+
| ID                             | Name       | Subnets                        |
+--------------------------------+------------+--------------------------------+
| ef38f7e8-439e-                 | sharednet1 | 749b6df4-6bcd-4d10-a01e-       |
| 44d0-b4c3-c9eff3c2c819         |            | 634348a76cb2                   |
+--------------------------------+------------+--------------------------------+

root@dlp ~(keystone)#
netID=`openstack network list | grep sharednet1 | awk '{ print $2 }'`

# create and boot an instance

root@dlp ~(keystone)#
openstack server create --flavor m1.small --image Ubuntu1604 --security-group default --nic net-id=$netID Ubuntu_1604

+-------------------------------------+------------------------------------------------+
| Field                               | Value                                          |
+-------------------------------------+------------------------------------------------+
| OS-DCF:diskConfig                   | MANUAL                                         |
| OS-EXT-AZ:availability_zone         |                                                |
| OS-EXT-SRV-ATTR:host                | None                                           |
| OS-EXT-SRV-ATTR:hypervisor_hostname | None                                           |
| OS-EXT-SRV-ATTR:instance_name       |                                                |
| OS-EXT-STS:power_state              | NOSTATE                                        |
| OS-EXT-STS:task_state               | scheduling                                     |
| OS-EXT-STS:vm_state                 | building                                       |
| OS-SRV-USG:launched_at              | None                                           |
| OS-SRV-USG:terminated_at            | None                                           |
| accessIPv4                          |                                                |
| accessIPv6                          |                                                |
| addresses                           |                                                |
| adminPass                           | 4PkvwmeLorP2                                   |
| config_drive                        |                                                |
| created                             | 2017-02-28T07:47:14Z                           |
| flavor                              | m1.small (0)                                   |
| hostId                              |                                                |
| id                                  | 2903f050-6871-475a-a0b8-714e5952bd93           |
| image                               | Ubuntu1604 (c8f1484e-b877-4447-b6ce-f1baa6bef) |
| key_name                            | None                                           |
| name                                | Ubuntu_1604                                    |
| progress                            | 0                                              |
| project_id                          | c654e2e098b14356b97b6e613775cc54               |
| properties                          |                                                |
| security_groups                     | name='default'                                 |
| status                              | BUILD                                          |
| updated                             | 2017-02-28T07:47:15Z                           |
| user_id                             | cf3c5cbcdd214707b91d322a69af038e               |
| volumes_attached                    |                                                |
+-------------------------------------+------------------------------------------------+

# show status ([BUILD] status is shown when building instance)

root@dlp ~(keystone)#
openstack server list

+--------------------+-------------+--------+---------------------+------------+
| ID                 | Name        | Status | Networks            | Image Name |
+--------------------+-------------+--------+---------------------+------------+
| 2903f050-6871      | Ubuntu_1604 | BUILD  | sharednet1=10.0.0.2 | Ubuntu1604 |
| -475a-             |             |        | 04                  |            |
| a0b8-714e5952bd93  |             |        |                     |            |
+--------------------+-------------+--------+---------------------+------------+

# when starting noramlly, the status turns to [ACTIVE]

root@dlp ~(keystone)#
openstack server list

+--------------------+-------------+--------+---------------------+------------+
| ID                 | Name        | Status | Networks            | Image Name |
+--------------------+-------------+--------+---------------------+------------+
| 2903f050-6871      | Ubuntu_1604 | ACTIVE | sharednet1=10.0.0.2 | Ubuntu1604 |
| -475a-             |             |        | 04                  |            |
| a0b8-714e5952bd93  |             |        |                     |            |
+--------------------+-------------+--------+---------------------+------------+
[2] Configure security settings like follows to access with SSH and ICMP.
# permit ICMP

root@dlp ~(keystone)#
openstack security group rule create --protocol icmp --ingress default

+-------------------+--------------------------------------+
| Field             | Value                                |
+-------------------+--------------------------------------+
| created_at        | 2017-03-10T06:45:14Z                 |
| description       |                                      |
| direction         | ingress                              |
| ether_type        | IPv4                                 |
| id                | faf40532-ceea-41ad-a5fb-11b857c022ce |
| name              | None                                 |
| port_range_max    | None                                 |
| port_range_min    | None                                 |
| project_id        | 763d3fd7411e4b42982d4d7022f1e335     |
| protocol          | icmp                                 |
| remote_group_id   | None                                 |
| remote_ip_prefix  | 0.0.0.0/0                            |
| revision_number   | 1                                    |
| security_group_id | cb6894d3-846b-4135-8cc6-25842b67c6a6 |
| updated_at        | 2017-03-10T06:45:14Z                 |
+-------------------+--------------------------------------+

# permit SSH

root@dlp ~(keystone)#
openstack security group rule create --protocol tcp --dst-port 22:22 default

+-------------------+--------------------------------------+
| Field             | Value                                |
+-------------------+--------------------------------------+
| created_at        | 2017-03-10T06:45:31Z                 |
| description       |                                      |
| direction         | ingress                              |
| ether_type        | IPv4                                 |
| id                | 15421d61-0343-40f9-8086-2e53e526248d |
| name              | None                                 |
| port_range_max    | 22                                   |
| port_range_min    | 22                                   |
| project_id        | 763d3fd7411e4b42982d4d7022f1e335     |
| protocol          | tcp                                  |
| remote_group_id   | None                                 |
| remote_ip_prefix  | 0.0.0.0/0                            |
| revision_number   | 1                                    |
| security_group_id | cb6894d3-846b-4135-8cc6-25842b67c6a6 |
| updated_at        | 2017-03-10T06:45:31Z                 |
+-------------------+--------------------------------------+

root@dlp ~(keystone)#
openstack security group rule list

+------------+-------------+-----------+------------+-----------------------+----------------+
| ID         | IP Protocol | IP Range  | Port Range | Remote Security Group | Security Group |
+------------+-------------+-----------+------------+-----------------------+----------------+
| 15421d61-0 | tcp         | 0.0.0.0/0 | 22:22      | None                  | cb6894d3-846b- |
| 343-40f9-8 |             |           |            |                       | 4135-8cc6-2584 |
| 086-2e53e5 |             |           |            |                       | 2b67c6a6       |
| 26248d     |             |           |            |                       |                |
| 9928f5fc-8 | None        | None      |            | None                  | cb6894d3-846b- |
| c94-4458-8 |             |           |            |                       | 4135-8cc6-2584 |
| 3a6-9a8678 |             |           |            |                       | 2b67c6a6       |
| 8fb5ee     |             |           |            |                       |                |
| bce04897-a | None        | None      |            | cb6894d3-846b-4135-8c | cb6894d3-846b- |
| 9b2-4b80-8 |             |           |            | c6-25842b67c6a6       | 4135-8cc6-2584 |
| 709-6fbcbf |             |           |            |                       | 2b67c6a6       |
| 459ef7     |             |           |            |                       |                |
| faf40532   | icmp        | 0.0.0.0/0 |            | None                  | cb6894d3-846b- |
| -ceea-     |             |           |            |                       | 4135-8cc6-2584 |
| 41ad-a5fb- |             |           |            |                       | 2b67c6a6       |
| 11b857c022 |             |           |            |                       |                |
| ce         |             |           |            |                       |                |
| fba7a2cb-  | None        | None      |            | cb6894d3-846b-4135-8c | cb6894d3-846b- |
| 03fa-4c11  |             |           |            | c6-25842b67c6a6       | 4135-8cc6-2584 |
| -aadd-ebab |             |           |            |                       | 2b67c6a6       |
| 85838be9   |             |           |            |                       |                |
| fe1ae047   | None        | None      |            | None                  | cb6894d3-846b- |
| -9bdd-43b1 |             |           |            |                       | 4135-8cc6-2584 |
| -b6bd-62fa |             |           |            |                       | 2b67c6a6       |
| 17442d87   |             |           |            |                       |                |
+------------+-------------+-----------+------------+-----------------------+----------------+
[3] Login to instance with SSH.
root@dlp ~(keystone)#
openstack server list

+--------------------+-------------+--------+---------------------+------------+
| ID                 | Name        | Status | Networks            | Image Name |
+--------------------+-------------+--------+---------------------+------------+
| 2903f050-6871      | Ubuntu_1604 | ACTIVE | sharednet1=10.0.0.2 | Ubuntu1604 |
| -475a-             |             |        | 04                  |            |
| a0b8-714e5952bd93  |             |        |                     |            |
+--------------------+-------------+--------+---------------------+------------+

root@dlp ~(keystone)#
ping 10.0.0.204

PING 10.0.0.204 (10.0.0.204) 56(84) bytes of data.
64 bytes from 10.0.0.204: icmp_seq=1 ttl=64 time=1.21 ms
64 bytes from 10.0.0.204: icmp_seq=2 ttl=64 time=0.760 ms

--- 10.0.0.204 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 0.760/0.986/1.213/0.228 ms

root@dlp ~(keystone)#
ssh ubuntu@10.0.0.204

The authenticity of host '10.0.0.204 (10.0.0.204)' can't be established.
ECDSA key fingerprint is SHA256:BnZk5iNzs2VZS+y3ndB48MptWfnMlGRgpk5aohhe5qo.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.0.204' (ECDSA) to the list of known hosts.
ubuntu@10.0.0.204's password: # the one you set during installation
Welcome to Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-66-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage
Last login: Fri Mar 10 14:40:17 2017
ubuntu@ubuntu-1604:~$    
# just logined

[4] If you using a virtual machine image provided from internet and do not know any password for login, Add SSH key-pair to login like follows. For self-created image, if you installed [cloud-init] package and enable [cloud-init] service in it, it's possible to set SSH key-pair for it. The default user of cloud-init setting for SSH is "ubuntu" user.
# create key-pair

root@dlp ~(keystone)#
ssh-keygen -q -N ""

Enter file in which to save the key (/root/.ssh/id_rsa):
# add public key

root@dlp ~(keystone)#
openstack keypair create --public-key ~/.ssh/id_rsa.pub mykey

+-------------+-------------------------------------------------+
| Field       | Value                                           |
+-------------+-------------------------------------------------+
| fingerprint | 0c:6e:65:b7:59:f5:8c:1a:54:5a:5c:dc:2e:3f:72:11 |
| name        | mykey                                           |
| user_id     | 9f3b26c5924a4bc78025e9a8453b2553                |
+-------------+-------------------------------------------------+

root@dlp ~(keystone)#
openstack keypair list

+-------+-------------------------------------------------+
| Name  | Fingerprint                                     |
+-------+-------------------------------------------------+
| mykey | 0c:6e:65:b7:59:f5:8c:1a:54:5a:5c:dc:2e:3f:72:11 |
+-------+-------------------------------------------------+

# run instance with key

root@dlp ~(keystone)#
openstack server create --flavor m1.small --image Ubuntu1604 --security-group default --nic net-id=$netID --key-name mykey Ubuntu_1604
root@dlp ~(keystone)#
openstack server list

+--------------------+-------------+--------+---------------------+------------+
| ID                 | Name        | Status | Networks            | Image Name |
+--------------------+-------------+--------+---------------------+------------+
| 22001099-3c0d-4211 | Ubuntu_1604 | ACTIVE | sharednet1=10.0.0.2 | Ubuntu1604 |
| -8b5a-2cc12ccb29d5 |             |        | 06                  |            |
+--------------------+-------------+--------+---------------------+------------+

# login with key

root@dlp ~(keystone)#
ssh -i mykey ubuntu@10.0.0.206
Welcome to Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-66-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage
Last login: Fri Mar 10 14:40:17 2017
ubuntu@ubuntu-1604:~$    
# just logined
[5] If you'd like to stop an instance, it's also possible to control with openstack command like follows.
root@dlp ~(keystone)#
openstack server list

+--------------------+-------------+--------+---------------------+------------+
| ID                 | Name        | Status | Networks            | Image Name |
+--------------------+-------------+--------+---------------------+------------+
| 22001099-3c0d-4211 | Ubuntu_1604 | ACTIVE | sharednet1=10.0.0.2 | Ubuntu1604 |
| -8b5a-2cc12ccb29d5 |             |        | 06                  |            |
+--------------------+-------------+--------+---------------------+------------+

# stop instance

root@dlp ~(keystone)#
openstack server stop Ubuntu_1604

root@dlp ~(keystone)#
openstack server list

+--------------------+-------------+---------+--------------------+------------+
| ID                 | Name        | Status  | Networks           | Image Name |
+--------------------+-------------+---------+--------------------+------------+
| 22001099-3c0d-4211 | Ubuntu_1604 | SHUTOFF | sharednet1=10.0.0. | Ubuntu1604 |
| -8b5a-2cc12ccb29d5 |             |         | 206                |            |
+--------------------+-------------+---------+--------------------+------------+

# start instance

root@dlp ~(keystone)#
openstack server start Ubuntu_1604

root@dlp ~(keystone)#
openstack server list

+--------------------+-------------+--------+---------------------+------------+
| ID                 | Name        | Status | Networks            | Image Name |
+--------------------+-------------+--------+---------------------+------------+
| 22001099-3c0d-4211 | Ubuntu_1604 | ACTIVE | sharednet1=10.0.0.2 | Ubuntu1604 |
| -8b5a-2cc12ccb29d5 |             |        | 06                  |            |
+--------------------+-------------+--------+---------------------+------------+
[6] It's possible to access with Web browser to get VNC console.
root@dlp ~(keystone)#
openstack server list

+--------------------+-------------+--------+---------------------+------------+
| ID                 | Name        | Status | Networks            | Image Name |
+--------------------+-------------+--------+---------------------+------------+
| 22001099-3c0d-4211 | Ubuntu_1604 | ACTIVE | sharednet1=10.0.0.2 | Ubuntu1604 |
| -8b5a-2cc12ccb29d5 |             |        | 06                  |            |
+--------------------+-------------+--------+---------------------+------------+

root@dlp ~(keystone)#
openstack console url show Ubuntu_1604

+-------+----------------------------------------------------------------------+
| Field | Value                                                                |
+-------+----------------------------------------------------------------------+
| type  | novnc                                                                |
| url   | http://10.0.0.30:6080/vnc_auto.html?token=9fc940fb-a680-4bbe-        |
|       | 92c1-883a50c4fc0e                                                    |
+-------+----------------------------------------------------------------------+
[7] Access to the URL which was displayed by the command above.
 
Tweet